package com.pega.eprescription;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.pega.eprescription.database.model.Prescription;
 
public class IllnessListAdapter extends BaseAdapter {
    
	ArrayList<Prescription> allPrescription;
	private static LayoutInflater inflater=null;
	Prescription tempValues=null;
	
	public IllnessListAdapter(Context activity, ArrayList<Prescription> allPrescription) {
		this.allPrescription=allPrescription;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return allPrescription.size();
	}
	
	@Override
	public Object getItem(int position) {
		return allPrescription.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		return allPrescription.get(position).getPrescripId();
	}
	
	 public static class ViewHolder{
         
         public ImageView image;
         public TextView name;
         public TextView date;

     }
	 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final int pos=position;
		ViewHolder holder = null;
		 View vi = convertView;
        
         if(convertView==null){
              
             vi = inflater.inflate(R.layout.illness_list_item, null);
              
             holder = new ViewHolder();
             holder.date = (TextView) vi.findViewById(R.id.date);
             holder.name=(TextView)vi.findViewById(R.id.name);
             
             holder.image=(ImageView)vi.findViewById(R.drawable.ic_launcher);
              
             vi.setTag( holder );
         }
         else 
             holder=(ViewHolder)vi.getTag();
          
         if(allPrescription.size()<=0)
         {
             holder.name.setText("No Data");
              
         }
         else
         {
             tempValues=null;
             tempValues = (Prescription) allPrescription.get(position);

              holder.name.setText( tempValues.getNamePre());
              holder.date.setText(new SimpleDateFormat("dd-MM-yyyy").format(tempValues.getStartDate()));

         }
         
         return vi;
	}

	
}